package com.xy.hms.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @author xiaye
 * @create 2020-02-23-12:37
 * 自定义的区域信息解析器
 *
 */

public class MyLocaleResolve implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String l = httpServletRequest.getParameter("l");
        Locale myLocael = Locale.getDefault();
//        如果参数中有l这个属性
        if (!StringUtils.isEmpty(l)){
            String[] split = l.split("_");
            myLocael = new Locale(split[0],split[1]);
        }
        return myLocael;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
